package rjeutsky.database.jdbc;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import rjeutsky.config.ConfigConstants;

public class Connector {
	public Connection getConnection() throws FileNotFoundException, IOException, SQLException, ClassNotFoundException {
		Properties props = new Properties();
		props.load(new FileInputStream(new File(ConfigConstants.PROPERTIES_PATH)));
		
		String url = props.getProperty(ConfigConstants.URL);
		String login = props.getProperty(ConfigConstants.LOGIN);
		String password = props.getProperty(ConfigConstants.PASSWORD);
		String jdbcDriver = props.getProperty(ConfigConstants.DRIVER);
		
		Class.forName(jdbcDriver);
		
		Connection connection =  DriverManager.getConnection(url, login, password);
		connection.setAutoCommit(true);
		
		return connection;
	}
}
